//配置axios的全局基本路径
axios.defaults.baseURL='http://localhost:8080'
//给Vue扩展一个属性$http
Vue.prototype.$http=axios;

//添加前置拦截器
axios.interceptors.request.use(config=>{
    //获取当前浏览器存储的token
    let token=localStorage.getItem("token");
    console.debug(token);
    if (token){//本地有存储的token
        config.headers["TOKEN"]=token;
    }

    return config;
},error => {
    Promise.reject(error);
})
// 如果没有登录 返回的数据 {"success":false,"message":"noAuth"}

axios.interceptors.response.use(config=>{
    console.debug(config)
    if(!config.data.success&&config.data.message==="noAuth"){
        //移除本地存储的数据
        localStorage.removeItem("token");
        localStorage.removeItem("loginInfo");

        //跳转到登录页面
        location.href="/login.html"
    }
    return config;
},error => {
    Promise.reject(error);
})


function getUrlData() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}


